setInterval(function () {
	let time = new Date()
	let nowHours = time.getHours()
	let nowMinutes = time.getMinutes()
	let nowSeconds = time.getSeconds()
	let nowYear = time.getFullYear()
	let nowMonth = time.getMonth() + 1
	let nowDate = time.getDate()
	let nowDay = time.getDay()
	let str = '日一二三四五六'
	let w = str[nowDay]
	const year = document.querySelector('.year')
	const month = document.querySelector('.month')
	const date = document.querySelector('.date')
	const day = document.querySelector('.day')
	const hours = document.querySelector('.hours')
	const minutes = document.querySelector('.minutes')
	const seconds = document.querySelector('.seconds')
	if (nowHours < 10) nowHours = '0' + nowHours
	if (nowMinutes < 10) nowMinutes = '0' + nowMinutes
	if (nowSeconds < 10) nowSeconds = '0' + nowSeconds
	year.innerText = nowYear
	month.innerText = nowMonth
	date.innerText = nowDate
	day.innerText = w
	hours.innerText = nowHours
	minutes.innerText = nowMinutes
	seconds.innerText = nowSeconds
}, 1000)
//创建全局的用于处理响应数据的函数
function handleKeyup(data) {
	//后端传过来的数据可能存在为空的情况，此时会传过来一个undefined值
	if (data.g === undefined) {
		document.querySelector('.suggest').innerHTML = ''
		document.querySelector('.suggest').style.display = 'none'
		document.querySelector('input[type="text"]').style.borderRadius = '10px 0 0 10px'
	} else {
		//不为空的情况下，将得到的数据写入页面中
		document.querySelector('.suggest').innerHTML = data.g.map(item => `
		        <li><a href="https://www.baidu.com/baidu?wd=${item.q}">${item.q}</a></li>
		      `).join('') || ''
	}
}
document.querySelector('input[type="text"]').addEventListener('keyup', e => {
	//动态创建script元素
	const script = document.createElement('script')
	//设置script元素的src属性，在URL中传递用于处理响应数据的函数名称给服务端
	script.src = `https://www.baidu.com/sugrec?prod=pc&wd=${e.target.value}&cb=handleKeyup`
	//将创建的 script 元素添加到 DOM 树结构中
	document.body.appendChild(script)
	//将添加到 DOM 树结构中的 script 元素节点删除
	document.body.removeChild(script)
	e.target.style.borderRadius = '10px 0 0 0'
	document.querySelector('.suggest').style.display = 'block'
}, false)
document.querySelector('input[type="text"]').addEventListener('blur',()=>{
	document.querySelector('.suggest').style.display = 'none'
	document.querySelector('input[type="text"]').style.borderRadius = '10px 0 0 10px'
},false)
document.querySelector('.suggest').addEventListener('mousedown', e => {
	if (e.target.nodeName === 'A') {
		document.querySelector('input[type="text"]').value = e.target.innerHTML
		window.open("https://www.baidu.com/baidu?wd="+e.target.innerHTML,"_blank")
	}
}, false)